typedef int STDataType;
typedef struct Stack
{
	STDataType* a;
	int top;		// 栈顶
	int capacity;  // 容量 
}Stack;
// 初始化栈 
void StackInit(Stack* ps)
{
	STDataType* tmp = (STDataType*)malloc(sizeof(STDataType) * 4);
	ps->a = tmp;
	ps->top = 0;
	ps->capacity = 4;
}
// 入栈 
void StackPush(Stack* ps, STDataType data)
{
	if (ps->top == ps->capacity)
	{
		STDataType* tmp = (STDataType*)realloc(ps->a, sizeof(STDataType) * ps->capacity * 2);
		ps->a = tmp;
		ps->capacity *= 2;
	}
	(ps->a)[ps->top] = data;
	ps->top++;
}
// 出栈 
void StackPop(Stack* ps)
{
	assert(ps->top);
	ps->top--;
}
// 获取栈顶元素 
STDataType StackTop(Stack* ps)
{
	assert(ps->top);
	return (ps->a)[ps->top - 1];
}
// 获取栈中有效元素个数 
int StackSize(Stack* ps)
{
	return ps->top;
}
// 检测栈是否为空，如果为空返回非零结果，如果不为空返回0 
int StackEmpty(Stack* ps)
{
	if (ps->top == 0)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
// 销毁栈 
void StackDestroy(Stack* ps)
{
	free(ps->a);
	ps->top = 0;
	ps->capacity = 0;
}
//队列的定义
typedef struct {
    Stack* Stack1;//入队列栈
    Stack* Stack2;//出队列栈
} MyQueue;
//队列的创建
MyQueue* myQueueCreate()
{
    Stack* pstack1=(Stack*)malloc(sizeof(Stack));
    Stack* pstack2=(Stack*)malloc(sizeof(Stack));
    StackInit(pstack1);
    StackInit(pstack2);
    MyQueue* queue=(MyQueue*)malloc(sizeof(MyQueue));
    queue->Stack1=pstack1;
    queue->Stack2=pstack2;
    return queue;
}
//队列的插入
void myQueuePush(MyQueue* obj, int x) {
    if(StackEmpty(obj->Stack1))
    {
        while(!StackEmpty(obj->Stack2))
        {
            int top=StackTop(obj->Stack2);
            StackPush(obj->Stack1,top);
            StackPop(obj->Stack2);
        }
    }
    StackPush(obj->Stack1,x);
}
//队列的删除
int myQueuePop(MyQueue* obj) {
    if(StackEmpty(obj->Stack2))
    {
        while(!StackEmpty(obj->Stack1))
        {
            int top=StackTop(obj->Stack1);
            StackPush(obj->Stack2,top);
            StackPop(obj->Stack1);
        }
    }
    int top=StackTop(obj->Stack2);
    StackPop(obj->Stack2);
    return top;
}
//返回队列头元素
int myQueuePeek(MyQueue* obj) {
    if(StackEmpty(obj->Stack2))
    {
        while(!StackEmpty(obj->Stack1))
        {
            int top=StackTop(obj->Stack1);
            StackPush(obj->Stack2,top);
            StackPop(obj->Stack1);
        }
    }
    int top=StackTop(obj->Stack2);
    return top;
}
//队列的判空
bool myQueueEmpty(MyQueue* obj) {
    return StackEmpty(obj->Stack1)&&StackEmpty(obj->Stack2);
}
//队列的销毁
void myQueueFree(MyQueue* obj) {
    StackDestroy(obj->Stack1);
    StackDestroy(obj->Stack2);
    free(obj);
}